home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / viewers / polyview / polyvw31.lha / Polyview3.1 / new / pvtime.c < prev    next >
C/C++ Source or Header  |  1993-08-13  |  17KB  |  480 lines

  1. /*****************************************************************************
  2.  * NCSA Polyview 3.1                                                         *
  3.  *                                                                           *
  4.  * Version 3.1 changes and additions by Gilles Bourhis.                      *
  5.  * Version 3 changes and additions by Marc Andreessen.                       *
  6.  * Version 2 by Brian Calvert.                                               *
  7.  *                                                                           *
  8.  * Software Development Group                                                *
  9.  * National Center for Supercomputing Applications                           *
  10.  * University of Illinois at Urbana-Champaign                                *
  11.  *                                                                           *
  12.  * This is BETA release software.  As such it may contain software bugs and  *
  13.  * exhibit inconsistencies.                                                  *
  14.  *                                                                           *
  15.  * Please send bug reports to polyview@ncsa.uiuc.edu.                        *
  16.  *                                                                           *
  17.  * Copyright (c) 1992 The Board of Trustees of the University of Illinois.   *
  18.  *                                                                           *
  19.  * Permission to use, copy, and modify this software and its                 *
  20.  * documentation for educational, research, and non-profit purposes is       *
  21.  * hereby granted, provided that the above copyright notice, the original    *
  22.  * authors names, and this permission notice appear in all such copies.      *
  23.  * Any distribution of this software requires the explicit and written       *
  24.  * authorization of the authors.                                             *
  25.  *                                                                           *
  26.  * The University of Illinois makes no representations about the             *
  27.  * suitability of this software for any purpose.  It is provided "as is"     *
  28.  * without warranty of any kind.                                             *
  29.  *****************************************************************************/
  30.  
  31. /* $Id: pvtime.c,v 1.3 93/08/13 13:59:30 gbourhis Exp $ */
  32.  
  33. #ifdef RCSLOG
  34. $Log:    pvtime.c,v $
  35.  * Revision 1.3  93/08/13  13:59:30  gbourhis
  36.  * Add transcript of commands, change Version Number.
  37.  * 
  38.  * Revision 1.2  92/09/24  03:13:14  marca
  39.  * Update text widget when sliders move.
  40.  * 
  41.  * Revision 1.1  1992/09/18  10:55:26  marca
  42.  * Initial revision
  43.  *
  44. #endif
  45.  
  46. #include "pv.h"
  47.  
  48. /* --------------------------- BITMAP INCLUDES ---------------------------- */
  49. #include "forward.bm"
  50. #include "forwardstep.bm"
  51. #include "stop.bm"
  52. #include "reversestep.bm"
  53. #include "reverse.bm"
  54.  
  55. /* Static local variable to indicate that slider movement triggered the
  56.    last action, so init_animate shouldn't be called from notify_animate. */
  57. static int last_action_from_gui = 0;
  58.  
  59. /* ----------------------------- local_reset ------------------------------ */
  60. static int local_reset(state_t *state, window_t *win, void *w)
  61. {
  62.   FOR_EACH_ACTIVE(win, state)
  63.     animate_reset(state, win);
  64.   init_animate(state, state->active_windows, win, TRUE);
  65.   return ST_OKAY;
  66. }
  67.  
  68. /* --------------------------- init_animate_fn ---------------------------- */
  69. int init_animate_fn(state_t *state, window_t *win, int reset)
  70. {
  71.   return init_animate(state, state->active_windows, win, reset);
  72. }
  73.  
  74. /* ----------------------------- init_animate ----------------------------- */
  75. int init_animate (state_t *state, window_t *active, window_t *palette, 
  76.                   int reset)
  77. {
  78.   animate_t *anim;
  79.  
  80.   assert (state->animate_window != NULL);
  81.   anim = (animate_t *)WIN_IMAGE(state->animate_window);
  82.  
  83.   if ((active == NULL) || (WIN_FRAMELIST(active) == NULL) ||
  84.       (WIN_FRAMES(active) == 1))
  85.     {
  86.       /* No active window or frame.  Empty the window. */
  87.  
  88.       /* Make everything unsensitive unless it already is. */
  89.       if (!anim->blank)
  90.         {
  91.           anim->blank = 1;
  92.           XmxSetSensitive (anim->frame, XmxUnsensitive);
  93.           XmxSetSensitive (anim->forward, XmxUnsensitive);
  94.           XmxSetSensitive (anim->forward_step, XmxUnsensitive);
  95.           XmxSetSensitive (anim->stop, XmxUnsensitive);
  96.           XmxSetSensitive (anim->reverse_step, XmxUnsensitive);
  97.           XmxSetSensitive (anim->reverse, XmxUnsensitive);
  98.           XmxSetSensitive (anim->frametext, XmxUnsensitive);
  99.           XmxSetSensitive (anim->delay, XmxUnsensitive);
  100.           XmxSetSensitive (anim->skip, XmxUnsensitive);
  101.           XmxSetSensitive (anim->frame_label, XmxUnsensitive);
  102.           XmxSetSensitive (anim->delay_label, XmxUnsensitive);
  103.           XmxSetSensitive (anim->skip_label, XmxUnsensitive);
  104.  
  105.           /* Set value of frame scale to 1. */
  106.           XmxAdjustScale (anim->frame, 1);
  107.           
  108.           /* Set value of skip scale to 0. */
  109.           XmxAdjustScale (anim->skip, 0);
  110.           
  111.           /* Set the frame text to nothing. */
  112.           XmxTextSetString (anim->frametext, "");
  113.         }
  114.     }
  115.   else 
  116.     {
  117.       /* First we need to unblank everything. */
  118.       if (anim->blank)
  119.         {
  120.           anim->blank = 0;
  121.           XmxSetSensitive (anim->frame, XmxSensitive);
  122.           XmxSetSensitive (anim->forward, XmxSensitive);
  123.           XmxSetSensitive (anim->forward_step, XmxSensitive);
  124.           XmxSetSensitive (anim->stop, XmxSensitive);
  125.           XmxSetSensitive (anim->reverse_step, XmxSensitive);
  126.           XmxSetSensitive (anim->reverse, XmxSensitive);
  127.           XmxSetSensitive (anim->frametext, XmxSensitive);
  128.           XmxSetSensitive (anim->delay, XmxSensitive);
  129.           XmxSetSensitive (anim->skip, XmxSensitive);
  130.           XmxSetSensitive (anim->frame_label, XmxSensitive);
  131.           XmxSetSensitive (anim->delay_label, XmxSensitive);
  132.           XmxSetSensitive (anim->skip_label, XmxSensitive);
  133.         }
  134.  
  135.       if (!last_action_from_gui)
  136.         {
  137.           /* Set the frame slider max and current frame number values. */
  138.           XmxSetArg (XmNmaximum, (int)WIN_FRAMES(active));
  139.           XmxAdjustScale (anim->frame, WIN_FRAMEID(active));
  140.           
  141.           /* Copy slider values and field value from the active window */
  142.           /* to the dialog's local variables. */
  143.           XmxAdjustScale (anim->delay, WIN_DELAY(active));
  144.           
  145.           if (WIN_FRAMES(active) / 2 - 1 > 1)
  146.             XmxSetArg (XmNmaximum, WIN_FRAMES(active) / 2 - 1);
  147.           else
  148.             XmxSetArg (XmNmaximum, 1);
  149.           XmxAdjustScale (anim->skip, WIN_SKIP(active));
  150.         }
  151.  
  152.       /* Frame text. */
  153.       XmxTextSetString (anim->frametext, FRA_NAME(WIN_FRAME(active)));
  154.     }
  155.   
  156.   return ST_OKAY;
  157. }
  158.  
  159.  
  160. /* ------------------------------ CALLBACKS ------------------------------- */
  161. static XmxCallback (GUItimeScaleCB)
  162. {
  163.   char line[MAXLINELEN];
  164.   int val = ((XmScaleCallbackStruct *)call_data)->value;
  165.   animate_t *anim = (animate_t *)WIN_IMAGE(gstate->animate_window);
  166.  
  167.   switch (XmxExtractToken ((int)client_data))
  168.     {
  169.     case PV_TIME_FRAME_SCALE:
  170.       PLAYAFILE ("/usr/lib/sounds/prosonus/instr/woodblock.aiff");
  171.       if (val != WIN_FRAMEID(gstate->active_windows))
  172.         {
  173.           animate_goto_num (gstate, gstate->active_windows, val);
  174.           sprintf (line, "time goto number %d\0", val);
  175.           GUIaddCommand (line);
  176.       TRANSaddCommand(gstate, line);
  177.           last_action_from_gui = 1;
  178.         }
  179.       break;
  180.     case PV_TIME_DELAY_SCALE:
  181.       PLAYAFILE ("/usr/lib/sounds/prosonus/instr/woodblock.aiff");
  182.       if (val != WIN_DELAY(gstate->active_windows))
  183.         {
  184.           time_delay (gstate, gstate->active_windows, val);
  185.           sprintf (line, "time delay %d\0", val);
  186.           GUIaddCommand (line);
  187.       TRANSaddCommand(gstate, line);
  188.           last_action_from_gui = 1;
  189.         }
  190.       break;
  191.     case PV_TIME_SKIP_SCALE:
  192.       PLAYAFILE ("/usr/lib/sounds/prosonus/instr/woodblock.aiff");
  193.       if (val != WIN_SKIP(gstate->active_windows))
  194.         {
  195.           time_skip (gstate, gstate->active_windows, val);
  196.           sprintf (line, "time skip %d\0", val);
  197.           GUIaddCommand (line);
  198.       TRANSaddCommand(gstate, line);
  199.           last_action_from_gui = 1;
  200.         }
  201.       break;
  202.     }
  203.  
  204.   return;
  205. }
  206.  
  207.  
  208. static XmxCallback (GUItimeVCRButtonCB)
  209. {
  210.   switch (XmxExtractToken ((int)client_data))
  211.     {
  212.     case PV_TIME_FRAME_FORWARD:
  213.       PLAYAFILE ("/usr/lib/sounds/prosonus/instr/braz_hi_shaker.aiff");
  214.       parse_line (gstate, "time forward", TRUE);
  215.       break;
  216.     case PV_TIME_FRAME_FORWARDSTEP:
  217.       PLAYAFILE ("/usr/lib/sounds/prosonus/instr/drm_clave.aiff");
  218.       parse_line (gstate, "time forward step", TRUE);
  219.       break;
  220.     case PV_TIME_FRAME_STOP:
  221.       PLAYAFILE ("/usr/lib/sounds/prosonus/instr/tama_base_drm.aiff");
  222.       parse_line (gstate, "time stop", TRUE);
  223.       break;
  224.     case PV_TIME_FRAME_REVERSESTEP:
  225.       PLAYAFILE ("/usr/lib/sounds/prosonus/instr/drm_clave.aiff");
  226.       parse_line (gstate, "time reverse step", TRUE);
  227.       break;
  228.     case PV_TIME_FRAME_REVERSE:
  229.       PLAYAFILE ("/usr/lib/sounds/prosonus/instr/braz_hi_shaker.aiff");
  230.       parse_line (gstate, "time reverse", TRUE);
  231.       break;
  232.     }
  233.  
  234.   return;
  235. }
  236.  
  237.  
  238. static XmxCallback (GUItimeVCRTextCB)
  239. {
  240.   char line[MAXLINELEN];
  241.  
  242.   sprintf (line, "time goto %s\0", XmxTextGetString (w));
  243.   parse_line (gstate, line, TRUE);
  244.  
  245.   return;
  246. }
  247.  
  248. static XmxCallback (GUItimeButtonCB)
  249. {
  250.   switch (XmxExtractToken ((int)client_data))
  251.     {
  252.     case PV_TIME_BUTTON_HELP:
  253.       GUIdoHelp (PV_TIME_BUTTON_HELP);
  254.       break;
  255.     case PV_TIME_BUTTON_OK:
  256.       /* NO NO NO NO! */
  257.       /* XtUnmanageChild (gstate->animate_window->base); */
  258.       parse_line (gstate, "window close time", TRUE);
  259.       break;
  260.     case PV_TIME_BUTTON_RESET:
  261.       PLAYAFILE ("/usr/lib/sounds/prosonus/sfx/tennis.aiff");
  262.       parse_line (gstate, "time reset", TRUE);
  263.       break;
  264.     }
  265.  
  266.   return;
  267. }
  268.  
  269.  
  270. /* ------------------------ create_animate_dialog ------------------------- */
  271. void *create_animate_dialog (state_t *state)
  272. {
  273.   window_t *win;
  274.   animate_t *anim;
  275.   Widget dialog_frame;
  276.   Widget time_form, buttons_form;
  277.   Widget dialog_sep;
  278.   Widget control_form, row_frame, row_form;
  279.   Widget frame_label, delay_label, skip_label;
  280.  
  281.   /* Make the new time window. */
  282.   state->animate_window = win = add_window 
  283.     (state, "time", DIALOG /* fuck it */, 
  284.      NULL /* init */,
  285.      NULL /* redraw */,
  286.      NULL /* animate */,
  287.      NULL /* event */,
  288.      notify_animate /* notify */,
  289.      destroy_animate /* destroy */);
  290.  
  291.   win->id = 0;
  292.   XmxSetUniqid (win->id);
  293.   win->base = XmxMakeFormDialog (state->base, "Polyview 3.1: Time Window");
  294.  
  295.   win->image = anim = (animate_t *)PVMALLOC (sizeof (animate_t));
  296.   /* When we start out we're not blank. */
  297.   anim->blank = 0;
  298.   
  299.   /* Frame for dialog box. */
  300.   dialog_frame = XmxMakeFrame (win->base, XmxShadowOut);
  301.  
  302.   /* Constraints for base. */
  303.   XmxSetConstraints 
  304.     (dialog_frame, XmATTACH_FORM, XmATTACH_FORM, XmATTACH_FORM, XmATTACH_FORM,
  305.      NULL, NULL, NULL, NULL);
  306.  
  307.   /* Form for dialog box components. */
  308.   time_form = XmxMakeForm (dialog_frame);
  309.  
  310.   /* Controls go in one big form. */
  311.   XmxSetArg (XmNhorizontalSpacing, 10);
  312.   control_form = XmxMakeForm (time_form);
  313.  
  314.   anim->frame_label = XmxMakeLabel (control_form, "Frame:");
  315.   anim->frame = XmxMakeScale
  316.     (control_form, GUItimeScaleCB, PV_TIME_FRAME_SCALE, NULL, 1, 100, 50, 0);
  317.  
  318.   /* Make frame and form to hold five buttons and one text widget. */
  319.   row_frame = XmxMakeFrame (control_form, XmxShadowEtchedOut);
  320.   XmxSetArg (XmNhorizontalSpacing, 5);
  321.   XmxSetArg (XmNverticalSpacing, 5);
  322.   row_form = XmxMakeForm (row_frame);
  323.   
  324.   anim->reverse = XmxMakeBlankButton 
  325.     (row_form, GUItimeVCRButtonCB, PV_TIME_FRAME_REVERSE);
  326.   XmxApplyBitmapToLabelWidget 
  327.     (anim->reverse, reverse_bits, reverse_width, reverse_height);
  328.  
  329.   anim->reverse_step = XmxMakeBlankButton 
  330.     (row_form, GUItimeVCRButtonCB, PV_TIME_FRAME_REVERSESTEP);
  331.   XmxApplyBitmapToLabelWidget 
  332.     (anim->reverse_step, reversestep_bits, reversestep_width, 
  333.      reversestep_height);
  334.   
  335.   anim->stop = XmxMakeBlankButton
  336.     (row_form, GUItimeVCRButtonCB, PV_TIME_FRAME_STOP);
  337.   XmxApplyBitmapToLabelWidget 
  338.     (anim->stop, stop_bits, stop_width, stop_height);
  339.   
  340.   anim->forward_step = XmxMakeBlankButton 
  341.     (row_form, GUItimeVCRButtonCB, PV_TIME_FRAME_FORWARDSTEP);
  342.   XmxApplyBitmapToLabelWidget 
  343.     (anim->forward_step, forwardstep_bits, forwardstep_width, 
  344.      forwardstep_height);
  345.   
  346.   anim->forward = XmxMakeBlankButton
  347.     (row_form, GUItimeVCRButtonCB, PV_TIME_FRAME_FORWARD);
  348.   XmxApplyBitmapToLabelWidget 
  349.     (anim->forward, forward_bits, forward_width, forward_height);
  350.   
  351.   anim->frametext = XmxMakeText (row_form);
  352.  
  353.   /* Activate callback; passed in as parameter. */
  354.   XmxAddCallbackToText (anim->frametext, GUItimeVCRTextCB, 0);
  355.  
  356.   /* Constraints for row_form. */
  357.   XmxSetConstraints 
  358.     (anim->reverse, XmATTACH_FORM, XmATTACH_FORM, XmATTACH_FORM, XmATTACH_NONE,
  359.      NULL, NULL, NULL, NULL);
  360.   XmxSetConstraints 
  361.     (anim->reverse_step, XmATTACH_FORM, XmATTACH_FORM, XmATTACH_WIDGET, 
  362.      XmATTACH_NONE, NULL, NULL, anim->reverse, NULL);
  363.   XmxSetConstraints 
  364.     (anim->stop, XmATTACH_FORM, XmATTACH_FORM, XmATTACH_WIDGET, XmATTACH_NONE,
  365.      NULL, NULL, anim->reverse_step, NULL);
  366.   XmxSetConstraints 
  367.     (anim->forward_step, XmATTACH_FORM, XmATTACH_FORM, XmATTACH_WIDGET, 
  368.      XmATTACH_NONE, NULL, NULL, anim->stop, NULL);
  369.   XmxSetConstraints 
  370.     (anim->forward, XmATTACH_FORM, XmATTACH_FORM, XmATTACH_WIDGET, 
  371.      XmATTACH_NONE, NULL, NULL, anim->forward_step, NULL);
  372.   XmxSetArg (XmNleftOffset, 50);
  373.   XmxSetConstraints 
  374.     (anim->frametext, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_WIDGET, 
  375.      XmATTACH_FORM, NULL, NULL, anim->forward, NULL);
  376.  
  377.   XmxSetArg (XmNmarginBottom, 2);
  378.   anim->delay_label = XmxMakeLabel (control_form, "Delay:");
  379.   anim->delay = XmxMakeScale 
  380.     (control_form, GUItimeScaleCB, PV_TIME_DELAY_SCALE, NULL, 0, 99, 0, 0);
  381.  
  382.   XmxSetArg (XmNmarginBottom, 2);
  383.   anim->skip_label = XmxMakeLabel (control_form, "Skip:");
  384.   anim->skip = XmxMakeScale 
  385.     (control_form, GUItimeScaleCB, PV_TIME_SKIP_SCALE, NULL, 0, 9, 0, 0);
  386.  
  387.   /* Constraints for control_form. */
  388.   XmxSetArg (XmNtopOffset, 10);
  389.   XmxSetConstraints 
  390.     (anim->frame_label, XmATTACH_FORM, XmATTACH_NONE, XmATTACH_FORM, 
  391.      XmATTACH_NONE, NULL, NULL, NULL, NULL);
  392.   XmxSetConstraints 
  393.     (anim->frame, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_FORM,
  394.      anim->frame_label, NULL, NULL, NULL);
  395.   XmxSetArg (XmNtopOffset, 10);
  396.   XmxSetConstraints 
  397.     (row_frame, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_FORM,
  398.      anim->frame, NULL, NULL, NULL);
  399.   XmxSetArg (XmNtopOffset, 10);
  400.   XmxSetConstraints 
  401.     (anim->delay_label, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM, 
  402.      XmATTACH_NONE, row_frame, NULL, NULL, NULL);
  403.   XmxSetConstraints 
  404.     (anim->delay, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_FORM,
  405.      anim->delay_label, NULL, NULL, NULL);
  406.   XmxSetArg (XmNtopOffset, 10);
  407.   XmxSetConstraints 
  408.     (anim->skip_label, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM, 
  409.      XmATTACH_NONE, anim->delay, NULL, NULL, NULL);
  410.   XmxSetConstraints 
  411.     (anim->skip, XmATTACH_WIDGET, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_FORM,
  412.      anim->skip_label, NULL, NULL, NULL);
  413.   
  414.   dialog_sep = XmxMakeHorizontalSeparator (time_form);
  415.  
  416.   buttons_form = XmxMakeFormAndThreeButtons
  417.     (time_form, GUItimeButtonCB, "OK", "Reset", "Help",
  418.      PV_TIME_BUTTON_OK, PV_TIME_BUTTON_RESET, PV_TIME_BUTTON_HELP);
  419.  
  420.   /* Constraints for time_form. */
  421.   XmxSetConstraints 
  422.     (control_form, XmATTACH_FORM, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_FORM,
  423.      NULL, NULL, NULL, NULL);
  424.   XmxSetArg (XmNtopOffset, 10);
  425.   XmxSetConstraints 
  426.     (dialog_sep, XmATTACH_WIDGET, XmATTACH_WIDGET, XmATTACH_FORM, 
  427.      XmATTACH_FORM, control_form, buttons_form, NULL, NULL);
  428.   XmxSetConstraints 
  429.     (buttons_form, XmATTACH_NONE, XmATTACH_FORM, XmATTACH_FORM, XmATTACH_FORM,
  430.      NULL, NULL, NULL, NULL);
  431.  
  432.   init_animate(state, state->active_windows, NULL, FALSE);
  433.  
  434.   XmxManageRemanage (win->base);
  435.   
  436.   return;
  437. }
  438.  
  439. /* ---------------------------- notify_animate ---------------------------- */
  440. int notify_animate (state_t * state, window_t * send_win, window_t * recv_win,
  441.                     int message, va_list args)
  442. {
  443.   int status;
  444.     
  445.   status = ST_OKAY;
  446.   
  447.   switch (message) 
  448.     {
  449.     case MSG_NEWACT:
  450.       /* Catch 'time reset', hopefully. */
  451.       init_animate(state, send_win, recv_win, TRUE);
  452.       last_action_from_gui = 0;
  453.       break;
  454.     case MSG_NEWFRAME:
  455.     case MSG_NEWDATA:
  456.     case MSG_VIEWCHG:
  457.     case MSG_CLOSING:
  458.     case MSG_RESET:
  459.       /* Only update the window if this is the current window. */
  460.       if (send_win == state->active_windows) 
  461.         {
  462.           init_animate(state, send_win, recv_win, FALSE);
  463.           last_action_from_gui = 0;
  464.         }
  465.       break;
  466.     case MSG_NEWPICK:
  467.     default:
  468.       break;
  469.     }
  470.   
  471.   return status;
  472. }
  473.  
  474. /* --------------------------- destroy_animate ---------------------------- */
  475. int destroy_animate (state_t *state, window_t *window)
  476. {
  477.   /* do absolutely nothing */
  478.   return ST_OKAY;
  479. }
  480.